#include "overviewwindow.h"
#include "ui_overviewwindow.h"

OverviewWindow::OverviewWindow(QDateTime time, QWidget *parent) :
    QFrame(parent),
    ui(new Ui::OverviewWindow)
    ,startRunTime(time)
    ,isPress(false)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_TranslucentBackground);
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);

    //显示软件运行的总时间
    mTime.setTimerType(Qt::VeryCoarseTimer);
    mTime.start(100);
    connect(&mTime,&QTimer::timeout,this,[=](){
        static int i = 5;
        i++;

        if(i % 10 == 0)
        {
            int dTime = startRunTime.secsTo(QDateTime::currentDateTime());
            int ss = dTime % 60;
            int mm = (dTime % 3600) / 60;
            int hh = dTime / 3600;
            ui->label_runTime->setText(QString("%1:%2:%3").arg(hh).arg(mm).arg(ss));
        }
        if(0)
        {
            QList<QPointF> point;
            point.append(QPointF(i++,qrand()%9000 + 500));
            ui->widget_detailLine->appendLine("鼠标操作数",point);
        }
    });

    QList<QPointF> point1,point2;
    for(int i = 0;i < 4;i ++)
    {
        point1.append(QPointF(i,qrand()%9000 + 500));
        point2.append(QPointF(i,qrand()%9000 + 500));
    }
    ui->widget_detailLine->appendLine("鼠标操作数",point1);
    ui->widget_detailLine->appendLine("键盘操作数",point2);
}

OverviewWindow::~OverviewWindow()
{
    delete ui;
}

#include <QMouseEvent>
#include <QDebug>
void OverviewWindow::mousePressEvent(QMouseEvent *event)
{
    if(event->type() == QEvent::MouseButtonPress)
    {
        pressPos = event->pos();
        isPress = true;
    }
}

void OverviewWindow::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->type() == QEvent::MouseButtonPress)
        isPress = false;
}

void OverviewWindow::mouseMoveEvent(QMouseEvent *event)
{
    if(!isPress)
        return ;
    QPoint dPos = event->pos() - pressPos;
    this->move(this->pos() + dPos);
}

void OverviewWindow::on_pushButton_close_clicked()
{
    emit closeThis();
}
